// onstSpringFunction.cpp: implementation of the ConstSpringFunction class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "constSpringFunction.h"
#include "PersistentFacade.h"
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
IMPLEMENT_DYNAMIC_CREATE(ConstSpringFunction, FunctionObject, FunctionObject::eSELCONSTSPRING)

ConstSpringFunction::ConstSpringFunction()
{
	m_pMinDis = NULL;
	m_pMaxDis = NULL;
	m_pDH = NULL;
}

ConstSpringFunction::~ConstSpringFunction()
{

}

BOOL ConstSpringFunction::Execute()
{
/*	ConstSpring* pSpring = GetConstSpring();
	if(pSpring == NULL)
		return FALSE;

	ConstSpringFunction* pCurFunction = this;
	while(pCurFunction != NULL)
	{
		if(pSpring == NULL)
			return FALSE;
		if(!pCurFunction->GetConstSpringPart(pSpring))
		{
			delete pSpring;
			return FALSE;
		}
		pCurFunction = static_cast<ConstSpringFunction*>(pCurFunction->NextRegister());
	}
	delete pSpring;*/
	return TRUE;
}

DOUBLE ConstSpringFunction::GetDisplacement()
{
/*	ASSERT(GetOwner());
	ASSERT(GetOwner()->GetOwner());

	Part* pPart = GetOwner();
	PartString* pString = pPart->GetOwner();

	return pString->HotDisplacement()*1.2/GetRegisterFunctionNum();*/
	return 0;
}

ConstSpring* ConstSpringFunction::GetConstSpring()
{
/*	ConstSpringSet* pSet = GetPersistentFacade().GetConstSpringSet();
	ASSERT(pSet);
	ASSERT(GetOwner());
	ASSERT(GetOwner()->GetOwner());

	Part* pPart = GetOwner();
	PartString* pString = pPart->GetOwner();
	ASSERT(!pPart->GetStandard().IsEmpty());
	pSet->SetDataStandard(pPart->GetStandard());
	
	DOUBLE dbDis = GetDisplacement();
	pSet->GetConstSpringSet(dbDis, pString->WorkLoad().length());

	ConstSpring* pSpring = pSet->GetFirstConstSpring();
	while(pSpring != NULL)
	{
		if(pSpring->IsLegal(dbDis))
		{
			pSet->Close();
			return pSpring;
		}
		delete pSpring;
		pSpring = pSet->GetNextConstSpring();
	}
	pSet->Close();*/
	return NULL;
}

BOOL ConstSpringFunction::GetConstSpringPart(ConstSpring* pSpring)
{
/*	ASSERT(m_pDH);
	ASSERT(m_pMaxDis);
	ASSERT(m_pMinDis);
	PartCrudeDataSet* pSet = GetPersistentFacade().GetPartCrudeDataSet();
	ASSERT(pSet);

	Part* pPart = GetOwner();
	ASSERT(pPart);

	ASSERT(!pPart->GetStandard().IsEmpty());
	pSet->SetDataStandard(pPart->GetStandard());

	DOUBLE dbDis = GetDisplacement();
	CString strRegular;
	strRegular.Format(_T("%s <= %g and %s >= %g and %s = %d"),
		m_pMinDis->GetSymbol(), dbDis, m_pMaxDis->GetSymbol(),
		dbDis, m_pDH->GetSymbol(), pSpring->DH());

	BOOL bResult = pSet->InstancePart(pPart, pPart->GetCustomID(), strRegular);
	pSet->Close();

	return bResult;*/
	return TRUE;
}

BOOL ConstSpringFunction::InstanceConstSpringPort()
{
/*	JointInfo info(this->GetOwner());

	JointFunction* pJoint = info.GetFirst();
	ASSERT(pJoint);
	while(pJoint != NULL)
	{
		ASSERT(pJoint->GetFunctionStyle() == FunctionObject::eCONSTSPRINGEXTERNALTHREAD_RH ||
		pJoint->GetFunctionStyle() == FunctionObject::eCONSTSPRINGEXTERNALTHREAD_LH ||
		pJoint->GetFunctionStyle() == FunctionObject::eCONSTSPRINGINTERNALTHREAD_RH ||
		pJoint->GetFunctionStyle() == FunctionObject::eCONSTSPRINGINTERNALTHREAD_LH ||
		pJoint->GetFunctionStyle() == eCONSTSPRINGEYE);*/

	return TRUE;
}